// import { createRouter, createWebHashHistory } from 'vue-router'  
// //导入组件
// import login from "@/views/login/login.vue" //@表示src目录
// import frame from "@/views/main/frame.vue"
// import { useAuthStore } from '@/stores/auth' //导入定义的用户信息类
// import myabsent from "@/views/absent/my.vue"  //导入两个定义的考勤视图
// import subabsent from "@/views/absent/sub.vue"
// import publish from "@/views/inform/publish.vue"
// import inform_list from "@/views/inform/list.vue"
// import inform_detail from "@/views/inform/detail.vue"
// import staffadd from '@/views/staff/add.vue'
// import stafflist from '@/views/staff/list.vue'
// import home from "@/views/home/home.vue"

// const router = createRouter({
//   history: createWebHashHistory(import.meta.env.BASE_URL), 
//   //路由配置使用hash模式   http://localhost:5173/#/login  前后端不容易冲突
//   routes: [
//     {
//       path: '/frame',
//       name: 'frame',
//       component: frame,
//       children:[
//         {path:'/absent/my',name:'myabsent',component:myabsent},
//         {path:'/absent/sub',name:'subabsent',component:subabsent},
//         {path:'/inform/publish',name:'inform_publish',component:publish},
//         {path:'/inform/list',name:'inform_list',component:inform_list},
//         {path:'/inform/detail/:pk',name:'inform_detail',component:inform_detail},
//         {path:'/staff/add',name:'staff_add',component:staffadd},
//         {path:'/staff/list',name:'staff_list',component:stafflist},
//         {path:'/',name:'home',component:home},
//       ]
//     },
//     {
//       path: '/login',
//       name: 'login',
//       component: login
//     }
//   ]
// })

// router.beforeEach((to,from) =>{
//   //判断用户是否登录，如果未登录就跳转到登录页面
//   const authStore = useAuthStore()
//   if(!authStore.is_logined && to.name !='login'){
//     //未登录且跳转到页面不是登陆页面
//     return {name:'login'}
//   }
// })

// export default router


import { createRouter, createWebHashHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import frame_routes from "@/router/frame"
import login_routes from "@/router/login"

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: frame_routes.concat(login_routes) //将新建的理由配置数组合并
})

router.beforeEach((to, from) => {
  // 判断用户是否登录，如果没有登录
  // 并且访问的页面不是登录页面，那么就要跳转到登录页面
  const authStore = useAuthStore()
  if(!authStore.is_logined && to.name != 'login'){
    return {name: 'login'}
  }
})


export default router





